package com.atwu.wl2022.util;
import java.util.Random;
import java.util.UUID;

/**
 * @Description 使用UUIDUtils生产发送给用户的邮箱验证码
 * @author wulejay
 */
public class UUIDUtils {


	public static String getUUID(){
		return UUID.randomUUID().toString().replace("-","");
	}

	public static String CAPTCHA(int n) {
		Random r = new Random();
		//分配一个空字符内存
		StringBuilder code = new StringBuilder();
		for(int i = 0; i < n; i++) {
			int type = r.nextInt(3);
			switch(type) {
				//大写字母
				case 0:
					//ASCII中大写字母的范围
					char c0 = (char)(r.nextInt(26) + 65);
					code.append(c0);
					break;
				//小写字母
				case 1 :
					//ASCII中小写字母的范围
					char c1 = (char)(r.nextInt(26) + 97);
					code.append(c1);
					break;
				//数字
				case 2:
					//生成0~9的随机数
					int m = r.nextInt(10);
					code.append(m);
					break;
				default:
					code.append(1);
			}
		}
		return code.toString();
	}
}
